package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.ManBean;
import com.project.mapper.IManMapper;
import com.project.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class ManServiceImpl implements IManService {
    @Autowired
    private IManMapper mapper;
    @Override
    public void add(ManBean man) {
        mapper.insert(man);
    }

    @Override
    public void del(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public void update(Integer id, String phone) {
        ManBean man = mapper.selectById(id);
        man.setPhone(phone);
        mapper.updateById(man);
    }

    @Override
    public List<ManBean> findAll() {
        return mapper.selectList(null);
    }

    @Override
    public ManBean findById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<ManBean> findByName(String name) {
        QueryWrapper<ManBean> qw = new QueryWrapper<>();
        //模糊查询，第一个参数为列名，第二个参数为值
        qw.like("m_name",name);
        return mapper.selectList(qw);
    }

    @Override
    public List<ManBean> findByBirthday(LocalDate startDate, LocalDate endDate) {
        QueryWrapper<ManBean> qw = new QueryWrapper<>();
        //大于
        qw.ge("m_birthday",startDate);
        //小于
        qw.le("m_birthday",endDate);
        return mapper.selectList(qw);
    }
}
